package example.documentbased.mainModule.controller
{
	import example.documentbased.mainModule.models.MainModel;
	import example.documentbased.mainModule.models.vo.EditorVO;
	import example.documentbased.mainModule.services.delegates.IMainServiceDelegate;
	
	import mx.collections.ArrayList;
	
	import org.etherframework.controller.ReactiveCommand;
	
	import raix.reactive.IObservable;
	import raix.reactive.Observable;
	import raix.reactive.Unit;
	
	public class RefreshAllCommand extends ReactiveCommand
	{
		private var _model:MainModel;
		private var _serviceDelegate:IMainServiceDelegate;
		
		public function RefreshAllCommand(model:MainModel, serviceDelegate:IMainServiceDelegate)
		{
			_model = model;
			_serviceDelegate = serviceDelegate;
			markAsInitialized();
		}
		
		override public function observable():IObservable
		{
			return processing(_serviceDelegate.getEditorsWithDocuments()
				.mapMany(function(editors:ArrayList):IObservable
				{
					_model.editors = editors;
					return Observable.value(new Unit());
			}));
		}
	}
}